package com.d0318.Z18;

import java.util.Random;

public class Test1 implements Runnable {
    int person=1;
    int num;
    public Test1(int num){
        this.num=num;

    }
    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                System.out.println("编号为" + person + "的员工从" + Thread.currentThread().getName() + "入场，拿到奖牌号" + num);
                if (person <= 30) {
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    person++;
                }else{
                    System.out.println("全部进场");
                    System.exit(0);
                }

            }
        }
    }
    public static void main(String[] args) {
        int num=0;
        Random r=new Random(1);
        for (int i = 0; i < 30; i++) {
            num = r.nextInt(100);
        }
        Test1 test1=new Test1(num);
        Thread thread1=new Thread(test1,"前门");
        Thread thread2=new Thread(test1,"后门");
        thread1.start();
        thread2.start();

    }
}
